Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
why "this" keyword in arrow function represents the object rather than global object(window)

I am learning the behavior of this keyword in ES6 class , before I have learnt that this keyword in object functions, represent the following :

  • In regular function, this represents the the current object.
  • In arrow function, this represent the global object(window).

So, when I worked with ES6 class I see that Class behave as Object when it is complied into JavaScript ,I see this behavior in console by putting this in a class method and this was representing the current class as Object as well as its prototype was Object.

For conceptual understanding, I make one Arrow function foo() and one Regular function bar() in a class AppComponent and print this keyword as follow:

enter image description here

I was expecting that this in foo() would represent global object(window) , because it is inside Arrow function in the Object and ,on the other side,in the bar() this represent the current object due to Regular function inside object which is AppComponent, but the output was:

enter image description here

bar() output is expected.

foo() output is unexpected.

So, my question is that why this represent the current Object Appcomnent rather than global object(window), because it is inside the arrow function in the object .

Please correct me if my concept is not correct in the question ,if it is correct then why I see the unexpected output. I would very thankful to you for your contribution.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda